<?php if(!defined('TYPO3_MODE')) die('Access denied.'); ?>


<?php

$filepath = urldecode($row['link_file']);
if(($row['link_type']==2) && !empty($filepath) && is_file($filepath)) {
    $parts = pathinfo($filepath);
    $filesizeString = '';
    $filesizenames = array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
    $filesize = filesize($filepath);
    if($filesize > 0) {
        $i = floor(log($filesize, 1024));
        $exponentialValue = pow(1024, ($i));
        $decimals = min(1, $i);
        $filesizeString = round($filesize/$exponentialValue, $decimals) . $filesizenames[$i];
    } else {
        $filesizeString = '0' . $filesizenames['0'];
    }
    echo '<span class="fileinfo">';
    if(empty($parts['extension'])) {
        if($noBrackets) {
            echo sprintf('%s', $filesizeString);
        } else {
            echo sprintf('(%s)', $filesizeString);
        }
    } else {
        if($noBrackets) {
            echo sprintf('%s, %s', strtoupper($parts['extension']), $filesizeString);
        } else {
            echo sprintf('(%s, %s)', strtoupper($parts['extension']), $filesizeString);
        }
    }
    echo '</span>';
}
